create procedure sp_ThemKH
	@TenKH nvarchar(30),@DienThoai char(15),@DiaChi nvarchar(50)
as
begin tran
	declare @MaKH int
	set @MaKH = 1
	while exists(select * from KhachHang where MaKH = @MaKH)
		Set @MaKh = @MaKH + 1
	insert into KhachHang(MaKH,TenKH,DienThoai,DiaChi)values(@MaKH,@TenKH,@DienThoai,@DiaChi)
	if(@@error <> 0)
	begin
		raiserror('Loi trong qua trinh them',16,1)
		rollback
		return
	end
commit